Refactoring of utils.js to use object and other refinements