Evasion of an infinite loop and add tests.