Fixed some bugs in the merge script