added end func to stop middleware execution