Fixed bug in BFS