Refactor the header logic.