Restructured the code to be more object oriented