Improve the infinte loop fix