Refactoring query communication into service