Simplify middleware processing.
Merge branch 'middleware'
Update docs.