Refactored code

Changed to using `switch` statements