fix queries generation