Works as a middleware