Implemented BFS