Fixed an issue with script nodes being removed incorrectly, fixes #3737.