Refactoring strong components and dfs