Clean up code. Change if-chains to switch/case