Fix bug in cropping logic