Academic attempt at Repair algorithm