this PR references #76 issue

Avoiding memory leaks for $script function object