When the ordering of ToC elements does not follow a natural flow, e.g. h2 (max root) => h3 => h4 => h1 (out of bounds), but can escape to above the root of the sections making up the ToC it was possible for the root element to become undefined.
A check is added such that root will always exist.
When the ordering of ToC elements does not follow a natural flow, e.g. h2 (max root) => h3 => h4 => h1 (out of bounds), but can escape to above the root of the sections making up the ToC it was possible for the root element to become undefined.
A check is added such that root will always exist.