Optimisation around calculating the depth of a node [clynt] [johan]