Cleaned up the middleware