Some fixes for mode switching