Finished initial refactoring