corrected infinite loop