Fixed code to be object oriented