Logic for dynamically selecting group winners

It still isn't perfect but its close enough that it can be improved later.