Add gulpfile build script

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