I think we should add an XXX comment here to see if we can write a function that will correctly wait for a window being closed.