more efficient min and max (better mutex management)