Replaced complex if statement with switch