Ending a program when a window is closed