SERVER-9038 refactoring of code for merging of results