refactored for node.js