fix issue with query generation