changing the structure of the script. rearranged into functions.