refactor for middleware usage
relieve middleware dependencies
Merge branch 'middleware'