Fixes to router for middleware