made training logic idempotent