diff --git a/progs/altree b/progs/altree
index 794f30b725b6ef8ba68e556da8247f4b78e33563..4d17d883e41dc85b9080c862121dfbfbcce67c9e 100755
--- a/progs/altree
+++ b/progs/altree
@@ -678,11 +678,12 @@ sub computeTreeStructure($) {
 		push @leafList, $node;
 	    }
 	}
-	if (scalar(@childNodeList) > 1) {
-	    $depth++;
-	}
 	if (scalar(@childNodeList) > 0) {
-	    $computeLeaf->(\@childNodeList, $depth);
+	    my $rec_depth=$depth;
+	    if (scalar(@childNodeList) > 1) {
+		$rec_depth++;
+	    }
+	    $computeLeaf->(\@childNodeList, $rec_depth);
 	}
 	foreach my $node (@leafList) {
 	    push @leaf_refs, $node;