use clamp instead of min, max