fix middleware mode