More performant fix for #4. We're losing ordering by graph size, but maybe that's not that bad anyway.