Update middleware, deal with edgecase.