previous version trying to fix the crash problem when training after training return with error