Unstubbing a lot of stubs, implementing a lot

All of the existing DB functions now unstubbed, and added one to
allow creation of subject types.
Also various functions above the DB level also unstubbed / tested
to be working with the real version.