Separated for loop into two loops.