Mostly finish implementation of managed user types.

Still a few wee things to fix, and more tests to write.