Add actual error message when adding duplicate, assorted small refactorings