Infinite loop corrected