implemented middleware option