Fixed bug in writeHeader()