refactoring and breaking up into better classes