modified the merging script