DFS implementation.