Refactored middlewares