We could use some private function with the duplicated code and a closure as argument or something like that. I didn't use it because it would be less readable in my opinion.