Add middlewares. Fix logging bug.