Refactor model to handle new middleware structure