refactoring queryBuilder