...and some minor cleanup.
Damn thing seems to be working.
I'm backfilling tests to cover the functionality that I developed incrementally in the Jupyter notebook and nail it down with concrete examples. No doubt I'll uncover some bugs.