Greatly simplified the implementation by using async.map instead of async.each.
Made the function 100% asynchronous.