mode switching cleanup