fixes #2470. Breaks the infinite loop that sometimes occurs with circular layout.