Convert chain of if/else blocks into a switch statement