adapted code for object oriented design