Modify merging of queries