Promote closewindow() to official function, rather than recreating it repeatedly as a lambda
Add a code-comment TODO