Look into async.each for this kind of stuff. It makes it much cleaner.