Added `get_namespace()` function

Takes a class name or object to find the namespace for.

Replaced a couple of places that try to do their own get namespace functionality.