added ability to query from references instead of ancestor