Can merge.length == 1 here? Above you handle that differently but not here. Maybe a helper function here would be good to share this code. Something like endMerge(...)