Clean events during processing

The events table is sorted and unique events are selected (duplicates are
ignored).  The events table is replaced with these selected rows.
Furhtermore, the event_ids are normalized so that they once again
correspond to the row id.