object oriented version of code