fix event handling for window closing