move this in a separate function. the previous code was simple to read, this not so much...