Fix bug with an infinity loop.