Refactored getNamespaces to a function