Wrote unit tests for util.js, fixed minor bugs (that testing revealed).'