Fixed Infinity loop bug