optimize for loop.