Fix infinite loop. PR#3347