Added close event before closing the window