Improved exit handling slightly