code of pruning method