modified train_model