fix window closing bug