Do pruning first, to avoid counting the lengths incorrectly