bug fixes in merge functions