re-wrote the addFunctionsToNamespace, still ugly, but at least not hacky