Better window handling when closing