added support for browser and node.js environments