updated sort and merge scripts