This function gets repeated a lot. Maybe we should pull it out?