Add clamp utility function