Small refactoring of query builder