code cleanup and namespace refactoring