generalized cropping function