refactoring query validator