replace_subtree now keeps track of depth.
Fix depth.