refoctoring and tried to catch window close event