First up, wrap that malformed rowspan stuff ,you know, the {{{}}} mess, in a try-catch that defaults to 1 if it blows up. Then, when you're pulling text, nuke the jQuery sortkey junk and those footnote brackets [123] before they trash your numeric columns. And run a cardinality check to catch horizontal duplication - because yeah, wikipedia tables sometimes legit repeat column names when they actually mean different things, not just because the layout got weird. Your detectHeaderRowIndex() function is honestly chefs kiss - it catches all those v t e variations whether they're spaced out, piped, or bracketed. I'm wondering tho if you're actually filtering out nested tables with table.tBodies or checking that row.parentElement === table, because if not, you're probably letting infobox rows slip through and mess with your column count? Anyway, if you keep iterating on this, those canonical test cases would make a killer regression suite