diff --git a/classes/MatsumotoImaiA.py b/classes/MatsumotoImaiA.py
index d892841219861087b40d3779e49bc166b2b06c19..d4baee30fa17c7aba2141e6595eb94393b3e8479 100644
--- a/classes/MatsumotoImaiA.py
+++ b/classes/MatsumotoImaiA.py
@@ -3,6 +3,9 @@
 
 from __future__ import absolute_import, print_function
 from sage.all import *
+from sys import exit
+
+from .helpers.sage_extensions import random_value, random_invertible_matrix
 
 from .helpers.AffineTransformation import AffineTransformation
 from .helpers.PrivateKey import PrivateKey
@@ -36,20 +39,23 @@ class MatsumotoImaiA(EncryptionScheme):
 
         ring = PolynomialRing(k, 'x')
         (x,) = ring.gens()
+        gx = ring.irreducible_element(n)
 
         q = len(k)
 
         # alle Kandidaten für theta werden gesucht
         thetas = []
         qn = q**n - 1
-        for theta in xrange(1, n - 1):
+        for theta in xrange(1, n):
             qd = q**theta + 1
             (common_divider, t, _) = xgcd(qd, qn)
-            if common_divider == 1:
+            if common_divider == 1 and t > 0:
                 thetas.append((theta, t))
 
         # ein zufälliges Theta wird ausgewählt
-        print(len(thetas))
+        if len(thetas) < 1:
+            exit('Kein theta gefunden')
+
         (self.theta, self.theta_invers) = thetas[int(random() * len(thetas))]
 
         S = AffineTransformation(
@@ -58,8 +64,7 @@ class MatsumotoImaiA(EncryptionScheme):
             random_invertible_matrix(k, n), random_vector(k, n))
 
         # der Erweiterungskörper wird gebaut
-        gx = ring.irreducible_element(n)
-        multivariate_ring = PolynomialRing(k, n)
+        multivariate_ring = PolynomialRing(k, 'x', n)
         extension_field = PolynomialRing(
             multivariate_ring, 't').quotient_ring(gx, 'T')
         self.extension_field = extension_field
@@ -67,7 +72,7 @@ class MatsumotoImaiA(EncryptionScheme):
 
         Sx = list(S(vector(multi_vars)))
 
-        pre_F = self.phi_invers(Sx)
+        pre_F = self.phi_inv(Sx)
 
         # F(X)
         post_F = pre_F * pre_F**(4**theta)
@@ -80,5 +85,4 @@ class MatsumotoImaiA(EncryptionScheme):
 
     def invert_MQ(self, msg):
         X = self.phi_inv(list(msg))
-        X = X**self.theta_invers
-        return vector(self.phi(X))
+        return vector(self.phi(X**self.theta_invers))
diff --git a/classes/MatsumotoImaiAExample.py b/classes/MatsumotoImaiAExample.py
index 228e8252ade232ac8d954ffc335d1a71086715a3..9f3450c48bde55e75c33172e3da9f16bf8bb6a85 100644
--- a/classes/MatsumotoImaiAExample.py
+++ b/classes/MatsumotoImaiAExample.py
@@ -3,7 +3,6 @@
 
 from __future__ import absolute_import, print_function
 from sage.all import *
-import copy as cp
 
 from .helpers.sage_extensions import random_value, random_invertible_matrix
 
diff --git a/keys/bsp_uov_old.priv b/keys/bsp_uov_old.priv
deleted file mode 100644
index b58b64b7dff26ab5dfef0d56e179a060c63bb4f9..0000000000000000000000000000000000000000
Binary files a/keys/bsp_uov_old.priv and /dev/null differ
diff --git a/test.py b/test.py
deleted file mode 100644
index 8d6db94ea84398147c526612bdfeab4b06a89d4b..0000000000000000000000000000000000000000
--- a/test.py
+++ /dev/null
@@ -1,28 +0,0 @@
-from __future__ import absolute_import, division, print_function
-from sys import exit
-from sage.all import *
-
-from classes.helpers.AffineTransformation import *
-
-k = GF(4, 'a')  # hat modulus x^2 + x + 1
-(a,) = k.gens()
-n = 3
-
-ring = PolynomialRing(k, 'x')
-(x,) = ring.gens()
-gx = x**3 + x + 1
-
-K = ring.quotient_ring(gx, 'X')
-
-q = len(k)
-
-thetas = []
-qn = q**n - 1
-print("qn =", qn)
-for theta in xrange(1, n):
-    qd = q**theta + 1
-    print("qd =", qd)
-    (common_divider, t, _) = xgcd(qd, qn)
-    if common_divider == 1:
-        thetas.append((theta, t))
-thetas
diff --git a/test_MIA.py b/test_MIA.py
new file mode 100644
index 0000000000000000000000000000000000000000..062882ae9bc1f1d00e7e7f1989e6e22b33e8cecf
--- /dev/null
+++ b/test_MIA.py
@@ -0,0 +1,27 @@
+#!/usr/bin/sage
+# -*- coding: utf-8 -*-
+
+from __future__ import absolute_import, division, print_function
+from sage.all import *
+
+from classes.MatsumotoImaiA import MatsumotoImaiA
+
+n = 5 # bitte prim wählen
+finite_field = GF(2**8, 'a')
+
+"""TEST MIA"""
+
+# Initialize simple MIA
+MIA = MatsumotoImaiA(finite_field, n)
+public_key = MIA.public_key
+
+# use a random vector
+msg = random_vector(finite_field, n)
+print("msg =", msg)
+
+# Nachricht verschlüsseln
+enc = public_key.encrypt(msg)
+print("public_key.encrypt(msg): enc =", enc)
+
+# Verifizieren, dass enc auch entschlüsselt wird
+print("MIA.decryt(enc):", MIA.decrypt(enc))