Still not in a working state, and still in middle of major rewrite. Committing just for an update.