fix query generator