fix bad for loop check