add iterative sum
add generic accumulation function