Reworked exit so that closing the main window exits the application