Use Math.min instead of ternary expression