add the reordering function