Replace complex if with switch.