corrected for loop conditional