Fixed hierarchy building logic to include empty tuples