fixed looping logic again