Updated `accumulate` function