You are not assured that paragraphs[1] exists in the current code. Wgen ignore_heading is true, you need to check that len(paragraphs) is stricly bigger than 1.