handling for window close and removing listeners