Converted lots of if-else constructs to switch statement
Small, but important bugfix