refactor to service instead of middleware