Editor exit/leaving function on error

Edited the editor exiting and leaving function setup so that it can
handle the case where an error occurs and the exiting/leaving functions
are put back into place.