Major overhaul of the Code. Less Global variables.