Fix potential infinite loop