fixing the DFS algorithm