fix multiple writeHeader calls