middle refactoring