moved summation statement to before where it is used.