Improve auto-name logic