Closing file handle properly