Refactored getIdentityFromString()