optimize lCRP
change loop to matrix for optimization