Refactoring to extract code in separate classes