improved script generation