We have a very similar function already in utils.