Fixed for loop for averaging