fixed bug introduces in latest refactor causing primary keys to be set mutiple times