Added source code for Middleware