refactor header generation slightly