Replacing double for loop with double iterator loop.