don't iterate the stack just to calculate the depth