Finalizing Middleware with test suite and fixes