Change the window closing operation to be cleaner