closing works but error when closing the main window