improved CycleDetector, other various refactorings