added function and test for query