fix a possible infinite loop