Fix Bugs of Infinity Loop