Rewriting train.py