[fix] Correctly iterate middleware.
[test] Added some tests for middleware integration.
[codestyle] Check explicitly for a function