Fixed a problem with closing (and saving) a duplicated file (closes #267).