fix repair function