added bfs algorithm