Bunch of fixes, and a new test harness that's usable in other projects