Finally fixed looping problems