Clean up the factory API a bit and fix some things in the tests