refactored the code into a class.