Updated middleware sample codes