Changed if/else loop to a switch loop