util.js: fix promise early resolution, indentation and code style