use as a middleware