add better error checking around mode change