refactored code to class