can we use Math.min / Math.max for this rather than a branch?