Refactored base58 Encode by extracting a function