I think that we should have a utility function that embeds this logic: it is duplicated in a few places.