Fix the detection of loop. Some tests with the timed matrix model don't
pass.