working merge algorithm