Fix switch statement bugs