prevent switch function from getting stuck