convert for each loop to scala for loop for performance