I think I've seen this code repeated somewhere—can we factor it out?