Refactor code to use extra methods and not optional parameters.

Fixed a case where file unsaved changes would be lost.