use references for middleware to fix problems on 5.3