preprocessEvents function

Pre-process events.