refactoring if statement for switch