refactoring, tests and documentation