Handle DuplicateKeyErrors by removing the duplicate unit from the repo
and decrementing the unit count.

Added another unit test to verify correct handling when a unit is in two
repositories.