changed order of summation