How about using Math.min() here?