Feature/fix middlewares

/to @ritch 
/to @bajtos