Refactored handleNamespace