Add function to do the relationship repair

Signed-off-by: Gawain Lynch <gawain.lynch@gmail.com>