fix possible infinite loop