Can you move this chunk to a separate function?