refactor logic for extracting initials