Improve robustness of header handling