Split into testable objects and started adding mocha tests