Fix for infinite looping