avoid reimplementing Math.min