diff --git a/src/py/fac_tools.py b/src/py/fac_tools.py
index f7459151ef1ec0766761eaa03f11b63f5faab276..f6f6293ed74d2fa0ea6cd9b9e6b077a3b0573b4f 100644
--- a/src/py/fac_tools.py
+++ b/src/py/fac_tools.py
@@ -140,3 +140,27 @@ def load_weights_and_biases(server,weights_and_biases):
     write_value_array(server, "HIDDEN", "BIAS", weights_and_biases['hidden']['biases'])
     write_value_multi_array(server, "HIDDEN", "WEIGHTS", weights_and_biases['hidden']['weights'])
     write_value_multi_array(server, "HIDDEN", "RWEIGHTS", weights_and_biases['hidden']['rnn_weights'])
+
+def init_weights_and_biases(server):
+    run_command(server,"INIT")
+    run_command(server,"WEIGHTS")
+    run_command(server,"INIT")
+    run_command(server,"RWEIGHTS")
+    run_command(server,"INIT")
+    run_command(server,"BIAS")
+    run_command(server,"TRAIN")
+    run_command(server,"LEARNING_RATE")
+
+def train_token_series(server, tokens, epochs):
+    run_command(server,"TRAIN")
+    run_command(server,"TOKENS")
+    for tok in tokens:
+        run_command(server,str(tok))
+    run_command(server,"DONE")
+    run_command(server,"TRAIN")
+    run_command(server,"RUN_SINGLE_EPOCH")
+    for i in range(0,epochs):
+        print("Training epoch: ",i)
+        ret = run_command(server,str(i))
+        if "SUCCESS" in ret:
+            break
diff --git a/src/py/tty1.py b/src/py/tty1.py
index 1e2b47ef8b3240bcc3f089ebb8bf734daf810a6d..0fbaa8f0b8653dbe751b3d356c1582fd958a1fa2 100644
--- a/src/py/tty1.py
+++ b/src/py/tty1.py
@@ -4,17 +4,13 @@ from fac_tools import run_command
 from fac_tools import fetch_all_values
 from fac_tools import get_fac_wrapper
 from fac_tools import dump_neural_network
+from fac_tools import init_weights_and_biases
 
 server = get_fac_wrapper("telnet")
 
-run_command(server,"INIT")
-run_command(server,"WEIGHTS")
 
-run_command(server,"INIT")
-run_command(server,"RWEIGHTS")
-
-run_command(server,"INIT")
-run_command(server,"BIAS")
+# Initialize the values
+init_weights_and_biases(server)
 
 weights_and_biases = dump_neural_network(server)
 
diff --git a/src/py/tty3.py b/src/py/tty3.py
index 1078dcdc3f900c0bb455037568a6461454bc5379..116ef4735f1ea12f26b8b02bf09a42b50c658857 100644
--- a/src/py/tty3.py
+++ b/src/py/tty3.py
@@ -4,6 +4,8 @@ from fac_tools import run_command
 from fac_tools import get_fac_wrapper
 from fac_tools import load_weights_and_biases
 from fac_tools import dump_neural_network
+from fac_tools import init_weights_and_biases
+from fac_tools import train_token_series
 
 from transformers import AutoTokenizer
 
@@ -22,17 +24,8 @@ decay_rate=100
 run_command(server,"HELLO")
 
 # Initialize the values
-run_command(server,"INIT")
-run_command(server,"WEIGHTS")
+init_weights_and_biases(server)
 
-run_command(server,"INIT")
-run_command(server,"RWEIGHTS")
-
-run_command(server,"INIT")
-run_command(server,"BIAS")
-
-run_command(server,"TRAIN")
-run_command(server,"LEARNING_RATE")
 # PicoRV does not have a floating point unit
 # All weights are stored as signed 32 bit integers
 # this means we have to do the math here and multiply
@@ -52,43 +45,11 @@ run_command(server,str(decay_rate))
 
 # Priming phase!
 # Upload and train token pairs first
-run_command(server,"TRAIN")
-run_command(server,"TOKENS")
-tok=tokens[0]
-run_command(server,str(tok))
-tok=tokens[1]
-run_command(server,str(tok))
-run_command(server,"DONE")
-run_command(server,"TRAIN")
-run_command(server,"RUN_SINGLE_EPOCH")
-for i in range(0,500):
-    ret = run_command(server,str(i))
-    if "SUCCESS" in ret:
-        break
+train_token_series(server, tokens[0:2], 20000)
+train_token_series(server, tokens[1:3], 20000)
+train_token_series(server, tokens[2:4], 20000)
 
 '''
-run_command(server,"TRAIN")
-run_command(server,"TOKENS")
-tok=tokens[1]
-run_command(server,str(tok))
-tok=tokens[2]
-run_command(server,str(tok))
-run_command(server,"DONE")
-run_command(server,"TRAIN")
-run_command(server,"RUN_EPOCHS")
-run_command(server,str(500))
-
-run_command(server,"TRAIN")
-run_command(server,"TOKENS")
-tok=tokens[2]
-run_command(server,str(tok))
-tok=tokens[3]
-run_command(server,str(tok))
-run_command(server,"DONE")
-run_command(server,"TRAIN")
-run_command(server,"RUN_EPOCHS")
-run_command(server,str(500))
-
 # Upload token series
 run_command(server,"TRAIN")
 run_command(server,"TOKENS")