Updated BFS for graph