Cleanup and test coverage

* Added comments and strict jslint cleanup (though not required)
* Refactored debug logging for testability
* Added remaining test coverage
* Fix for gulp cover task