Only relax bounds checking for the last element of insert paths

Before this change, the bounds check for insertAfter/insertBefore would
be relaxed for all elements of the path, not just the last one.