add switch statement

removed global $CONFIG as it's not needed here
changes multiple ifs to a switch statement