fix bug in patch merge fuction