I think it's a bit odd that this function can return a different structure, depending on whether we're using groups or not. I also wonder if it is possible to iterate the options in one sweep, rather than in 2 separate reduce functions. We could see perf issues in large lists otherwise.