Working version of pruning code.