add some protection against infinite loop