Changing if/else to a switch, and cleaning up code