Refactored for mocha test and npm + browserify compatibility