implemented bfs