updated query generation