fix expansion query write out