Implemented Clamp function