modified DFS