rewrite of script generation