added some merging logic