More robust code for event processing