update depth when doing recursion