New function to generate valid instance names.
Fix crash when adding unnamed instances.