Implementing Feifei's fix for primary keys