Implemented mask auto-crop optimization