Fix accomulator issues

This is a proposed fix.

@thatch45 should review this code since it's exposing extra data in a state module's context as a function global.