Fixed two for loops