Fix bug when item has no tag

Note testing for typeof p.tags == "object" doesn't ensure it is not
null so doesn't ensure has length property.