restructured the code to be more object oriented