Finished first pass of refactoring