Actually, why not just pass the res into the onEnd() function?  Then "result" wouldn't have to be in the closure scope.  Also, would there be any state where "failed" array can ever be bigger than length of one?