Improved windowClosing handling.