inner loop updating wrong accumulating variable

Compare to the equivalent statement in the outer loop at line 76.