Reworked the way we handle header and footer

This is safer, and more 'correct' and elegant. Plus, it's harder to
forget about the footer.