Wrote pruning function.