Maybe this could be extracted as a util function?