code for bfs