change to middleware