baseline BFS implementation