re-ordered output data rows to group by reference