refactor query builder.