Update idle event handling to fix crash in idle event callback