Fixed error caused by duplicate entries in database, the primary key is now checked if it is in the database already. Added test for it too
fixed and merged conflicts