Add middleware for 4.1