updated to use switch statements rather than endless elseif statements