Most of #1794 done, except for nodes not in the same tree