function restructuring into individual scripts