Implemented function of middleware