use an explicit accumulator to reduce memory consumption