Made tests work (fixed one bug that somehow made it into this rev even though I already fixed it once, one bug that had to do with my understanding of the undocumented api :)
Should be good to pull.
A little beautification