bugfix query construction