CDB-4232 Encapsulate a bit of code to avoid repetition (from a CR by Kartones)