Add a loop count to avoid an infinite loop.