updated merge logic