charset extracted as constant
Added warned_unsaved constant
Some code rewritten in Java 8 style
Added close on exit