Code optimizations

Switched from IF statements to SWITCH statements