updated merge function with a more generic name