bugfix query building