Updated version. Pruned database before doing an insert. This fixes the scenario where you want to add the same secret code you just deleted.