fixed infinite loop issue