factor out header parsing