Implementation of crop function