Fixed infinite loop

fixed infinite loop