fixed potential infinite loop