Refactoring + pruning of trees to given depth