abstract fn out into a middleware