Refactor namespaces

See #137 for details.