Fix TEI serialisation error, improve header processing.