Fix bugs in header parsing