GridQuery refactoring