Made loop detection better.

We now can change the loop depth easily.  We also only iterate over the
loops only once per generation. I have the depth defined as 120 since
this was the largest known repeating pattern that fits in our grid
(Figure eight on pentadecathlon).  We can make it smaller though if it
is too much of a performance hit.  We’ll just miss the repeat.