Program exits cleanly when window is closed