Middleware registration refactoring