when replacing children having children of their own, things fail

this is a WIP with failing tests and some tentative fixes that seem to be wrong.