fix a bug for determing when to exit the emergency mode