fix order for middleware