Rewrote header.js mostly from scratch. It's much better organised and much better documented.