added events for before/after window close