cleaned up train_models function