updated the code to be more object oriented