middleware refactoring