It's still ugly, but I've finished the component group calculation.

Next, I’ll go through the damn thing again, to make it all hang
together.