Implemented Exit command and warning on Closing event. Additional refactoring of using references.