class refactoring and testing