train function works