naive bfs implemented