Finish training function