Much cleaner design

Replaced just about everything. The design is now much cleaner and more
functional (in the language sense). It may be a bit slower, but if it
is, it's not by much. It is also much cleaner, easier to understand,
and easier to modify.