error/panic/abort: move writeHeader to end of call-chain