bugfix for nested queries