FIX: Ensured creation of script directory before applying template.
FIX: Corrected usage of undefined variable name.