add middleware, some style changes
Merge branch 't7_middleware'