Major cleanup of event system code