Added query_relations functionality