Changed a while loop to a for loop.