modified to replace the evaluated script in place