Automated attaching of heads (UPDATE: working)

I created a script "HeadHandler" containing functions "AddHead" which takes a body GameObject already in the scene, the resource name for the desired head, and the root bone from which the integration should start, and "RemoveHead", which takes the body and head GameObjects.
This already works in principle, I created a test scene "rigtest_xexano" with a dummy body which has the script attached for testing: AddHead is called by pressing H, a head prefab containing the identical rig as the body is then automatically parented and its bones from "Neck" onward are parented to the corresponding body bones. With the J key, the head can be removed again.