Make sure script.parentNode exists before removing the script element