Fully working, results more or less as expected.

At some point in the future, I may decide to attempt to thread this, but
for now, this is it.