written in closure (will work in node.js)