Merge function definition
Implemented merge function