restart function and checkpoint