fixed error that do not close the file handle