Small BFS optimzation