Implemented find_cycle