Improved entity name function