Refactoring, cleanup