uses BFS