checking for infinite loops