added function to transfer sorted to unsorted arrays