Refactoring handling of async call in for loop