Implemented save on close dialogs

Also minor refactoring for GUI collection in core