Shorten redundant if-else statement