fix some endless looping problems