Add Gulp support

Some modifications to the main js file were also required in order to
make JSHint pass.