Refactor mergeData method to be testable