@Korvin: it's only replacing keys that exist which are explicitly defined using set(). there was no need to add any further check.
@Hawkee: that's an excellent idea thanks :)