Could you please move this logic to an external function?