Refactor controller logic to service.