Implement  some fixes for router middleware