compactified some loops in util.js