Move all code into module.exports function