finished most refactoring