now resets terminal correctly upon exist