Step one -- use destructuring instead of first/second
Step two -- destructure directly in the for
Step three -- collapse nested for's, don't flatten

It's strictly possible that this doesn't do what it used to do (due to
the recursive nature of flatten), but I doubt it