Use correct indexes for loop.