Add check for internal duplicates on import

Let me know what you think. If this looks OK, I'll write a few tests.
The key can be used in the error message, though I'm not sure that adds much value.