update namespace handling to try to work in both browser and Node.js