This loop feels bad, but I don't have a proposal for fixing it.  Feel free to ignore this comment unless you have a better idea for making it clearer / more elegant.