Use clamp function in a more sensible way