Corrected a bug with double opening of a file.