I just realized that this is a different thread than I expected.
I had my problems with this script too. So I developed a preset which got rid of most of the quirks (not all though).
Try to install the preset and see if it works better for you:
One example for the quirks are, that some settings windows from Menubar-Apps are never registered as frontmost and do not close with the red button. For example 'AlDente' in my case. So whenever I need to change anything in this app I have to deactivate/activate BTT.
You can always open the Hovered/Focused UI Element Viewer to see what windows is registered as frontmost/hovered.
You get there by clicking on your trigger > Advanced Conditions (right panel) > Hovered/Focused UI Element Viewer.