Updated middleware