Fixed code that finds xy extent for patch cropping