Reworked some suboptimal logic found in create_script()