fixed wasted API call in a loop.