Added cropping

- various improvements and simplifications
- updated unittest