merge sub-routine