Improve connected bfs search