Add proper namespace to class instances

Fixes #1779