Fixed recursive DFS method