Refactoring

Applying node best practices

http://nodeguide.com/style.html
Split the single file into logic and executable

The logic one now is a module.