Preliminary cycle detection.  Still needs some work