Resturctured to be more object oriented