Aggregate factory

Replaces #29 incorporating @kelvinj's work. This looks nothing like the original #29 so it has a new PR so that we can move on from here.
@kelvinj What do you think? I'll make this change if you :+1: it. (I'm :+1: FTR)