More fixes to file writing.