Fix a possible infinite loop