WIP: Refactor code to support arbitrary rollups

Feedback welcome!