changed query generation