Added check for name conflicts and improved selection.