Remove the 3rd loop. 2 is enough.