not using minBy as it is not stable