refactoring query module to pass acceptance tests [ci skip]