Depth fixed, factored out d3 code