Multi realm support PG

Initial support for multiple realms, though it is a bit flakey.