Source code refactoring. Extracted out common functionalities into merge...

Source code refactoring. Extracted out common functionalities into merge.d functions .