Added train function