Refactor saving of window geometry.

Closes #154