switch from DFS to BFS