Refactor getNamespaces and add factory method.