could use a defer for closing the file handle.