Fixed the infinite loop