added write-script function