Correct the implementation of accumulate

Fixes #23