Refactoring requestQuery Function