added clamp code