refactored code into class