Re-wrote basically everything.

Just what the name says. Changed the plan for the whole thing, and made
appropriate changes.