Some formatting cleanup and comment-adding
A more basic way to make the close button work