Optimized nested for loops on utils.js