Fix window closing issues