Put the apply out of the for loop