Added a handler for various exit scenarios the script can encounter