refactoring to a class