Is there a way to shorten the code?