This is a huge set that changes the semantics of get_typed_class() and get_typed_instance() to take a reference class name for proper typing. I have only smoke-tested it, but it fixes several issues with returning incorrectly-typed instances that I know of. A healthy amount of testing would be appreciated :)