Add in cycle detection code.