refactored to repair train_X_Y directory