implemented writeHeader