Reorganized the switch statement a bit