Refactor QueryBuilder