Fix the window close event, add some forgetten code to the events.