refactor the querygenerator