update middleware implementation