Refactor based on changes in Middleware