Converted to browserify, mild refactor