Fix middleware instance issue