Fix middleware