Make header parsing more robust