Properly close file