- Fixing duplicate primary key issue.

I (in a moment of insanity) forgot the move the PK generation down to the loop
that updates/creates new keys when I made it possible to update items in bulk.

Fixing that here.