Added bugfix: can't close file if open throws exception