Added clipping function.