bfs updated (not test)