Set up middleware model