Scaling and clamping functions added