Replacing a section in a subpart correctly

When replacing an entire existing section, we should replace it in the 'right' place by calculating it's parent correctly. A section might be in a subpart. Previously, the code assumed that the parent of a section was always the root. That assumption is obviously incorrect.