added merging logic