Fixed loop in mode changing