changed middleware functionality