Adapted from TCRF.