add calculation for maximum depth