Improved cropping and scanning python code