Refactor middleware mixin.