made critical fix to the model training function.