change sort and array merge algorithm