Correct bug when closing window