Tag index

Just starting on this, not for merging yet, but feedback welcome.
Ah, I see this is copied from below. I think we can yank this function.