This patch changes the order of the output, which isn't tested.

Please fix.  I hate to ask this, but would you please add a test that shows the original output order is preserved?