fix header parsing with a slightly cleverer approach (though clever it
is not) and tests accordingly