Restructued the code to use a class.