Fixed Infinite Loop Bug