Better header code

Needs a big clean up and refactoring, but will do it some other day