refactor for new style middleware