completed porting to tquery r57.0