Improve mode switching code
Improve mode switching code

mediagreenhouse/spontaneous,opendesk/spontaneous,mediagreenhouse/spontaneous,opendesk/spontaneous,SpontaneousCMS/spontaneous,mediagreenhouse/spontaneous,SpontaneousCMS/spontaneous,SpontaneousCMS/spontaneous,opendesk/spontaneous