Fix misplaced main window deletion