fix the switch function