Added separate event processing loop