new solution to bfs