Refactoring to break up logic into reusable modules

The new layout will allow for integration with JSLint and JSHint