Fixed middleware bug