Guard event handling against infinite loops