fix middleware bug