Implemented a new switch

Replaced the crazy if else loop with a switch statement, much nicer to
read now and easier to understand by far.