Refactored merging functionality into a function to support merging from multiple data sources (parametrized), as well as to improve software design.