modified function doquery