Improved BFS