Minor optimization in bfs code.