Moving event objects into if block