Added optional clipping function