added end condition frame work(query_each);