Rework with middleware and proper parameter passing