added a better DFS