updated to detect parent tags.