Refactor middleware tests.
Cleanup.