Add event processing code