changed to object oriented, resolving bug