Extract off more general-purpose code.