Fixed query builder bug