moved factory logic out of Node.js to Factory.js