Improved handling of duplicate entries
Fixed save to db.