Fix a potential infinite loop