Update train function