Optimize the loop.