Fixed the grouping of events. Lots of other changes.