restructuring of main script wip