bug fix infinite loop