Reverts the ranks, fixes the loop.