fixed issue in switch function