Fix possible infinite loop