The biggest problem was simply that the length of children expansions was not accounted for when skipping over the parent... this took a lot of arduous debugging, but it finally works!