Improved naming algorithm