Refactor Script

Made main macro creation a function