Fix the double fclose crash in the scripting engine and add comments.