Middleware response callback refactor