adding the train function