further refactoring for node/browser simplicity