Started work on test harness using grunt + mocha.

Factored some code, small bug fixes.