updated handling of the end of the script