utils.js refactoring