Fixed DFS algorithm