modified to deeply copy for script