(WIP) Mainline compiles; tests don't.
Refactor complete.