Change BFS search to DFS search in sortByThread