finally, fix infinite loop bug