refactoring query service