Clamp function fixed