Middleware for pi