Updated extension to be a middleware