Refactor event processing.