Refactor this code:

###

# PowerShell script to convert PPTX files to UTF-8 encoded plain text

$dir = "C:\path\to\directory"
$filter = "*.pptx"
$outputDir = "C:\path\to\output\directory"

# Create a new PowerPoint application object
$ppt = New-Object -ComObject PowerPoint.Application

# Disable alerts and set options
$ppt.DisplayAlerts = "None"
$ppt.Options.SaveInterval = 0
$ppt.Options.RelyOnVML = $false
$ppt.Options.RelyOnCSS = $false
$ppt.Options.ShowPlaceholders = $false

# NAME_1 through all PPTX files in the directory and convert to plain text
Get-ChildItem -Path $dir -Recurse -Filter $filter | ForEach-Object {
    $presentation = $ppt.Presentations.Open($_.FullName)
    $plainText = $presentation.SaveAsText()
    $presentation.Close()
    
    # Write the plain text to a new file in the output directory
    $outputPath = Join-Path $outputDir ($_.BaseName + ".txt")
    $plainText | Out-File -Encoding UTF8 $outputPath
}

# Quit the PowerPoint application
$ppt.Quit()
 Provide your response in exactly 3 paragraphs (separated nearby paragraphs with 3 aterisk symbols ***).
user