corrected script exit method