refactoring to use middleclass