Refactor the whole code base.

I'm still working on this, so I don't even really want you to merge it just yet,
but I'd like for you to take a look at this.