extracted reordercolumns script since it will be useful elsewhere