Fix for duplicate key error on some updates