Rewrote BFS