detect & remove cycles in paths