Change complex loop into Promise.all invocation.