Fixed bug while cleaning up handlers during window close.