Made the script generation more general