fixed looping problems