Refactor header reading a little