more restructuring and initialization of run script