Corrected final loop for ensemble averages