Fix bugs in merge