fix infinite loop problem