Close all Safari tabs with a specific name

I am looking for a simple AppleScript to close all Safari tabs that have a specific name, much like this one below does for Google Chrome tabs. I have searched Google and the forum here for scripts that do this. but haven't come up with anything.

tell application "Google Chrome"
	set _W to a reference to every window
	
	repeat with W in _W
		close (every tab of W where the title contains "Linguee")
	end repeat
end tell

If anybody could come up with something for me I'd be very grateful!

Try:

tell application "Safari"
	set _W to a reference to every window
	
	repeat with W in _W
		close (every tab of W where the name contains "Linguee")
	end repeat
end tell

It appears to work (as it closes multiple tabs with that name, and no others), but it gives me the following error message:

error "Safari got an error: Can’t get item 4 of every window. Invalid index." number -1719 from item 4 of every window

EDIT: I came up with the following script and it appears to work. Can somebody tell me if they see any potentials or problems errors with it?

set closeTab to "Linguee" as string
tell application "Safari"
	close (every tab of window 1 whose name contains closeTab)
end tell

EDIT 2: It appears that only works if those tabs are in the most recently activated Safari window...

EDIT 3: If I put in multiple "tell window" lines it works (as shown below), but I don't always have the same amount of windows open and I'd rather keep this script as simple as possible. Is there a way to have AppleScript tell Safari to close tabs across all open windows?

set closeTab to "Linguee" as string
tell application "Safari"
	close (every tab in window 1 whose name contains closeTab)
	close (every tab in window 2 whose name contains closeTab)
	close (every tab in window 3 whose name contains closeTab)
end tell

EDIT 4: I think I came up with something that works across multiple windows and doesn't give any errors.

set closeTab to "Linguee" as string
tell application "Safari"
	set _W to a reference to every window
	
	repeat with W in _W
		close (every tab of W where the name contains closeTab)
	end repeat
end tell

Odd. My script didn't give me any errors.

That said, if your script is working, keep an eye on its behavior. If it behaves as desired over a days worth of use, I'd go with it.