Refactor to fix issues with namespaces