fix infinite looping