improving version using class. Still needs lots of work