Reorganize script structure