move this to the middleware lines 36-52.