diff --git a/AstBuilding.py b/AstBuilding.py
index dbf919b220c100236f64e714c2d6dfc4035cb5b9..d72299933de7a5125747c62696be5c66b7667e67 100644
--- a/AstBuilding.py
+++ b/AstBuilding.py
@@ -109,33 +109,32 @@ def arrayClassMemory(types):
 def codeGenPrep(ASTs):
     interM = []
     types = ['boolean', 'byte', 'char', 'int', 'short'] # All possible types
-    j = 0
+    classNodes = []
+
     for t in ASTs:
         classInterNode = t[1].typeDcl
-        types.append(classInterNode)
-
-        # assign each type a position in the subtype testing table
-        classInterNode.subTypeOffset = j * 4
-        j += 1
-
         if classInterNode.__class__.__name__ == "ClassNode":
-            classInterNode.populateSizeAndFieldOffset()
-            classInterNode.populateMethodOffset()
+
             types.append(classInterNode.name)
+            classNodes.append(classInterNode)
         else: # interfaceNode, get their methods to prep for SIT
             interM += classInterNode.methods
 
+    # store SIT and subtype table size
+    for i in range(len(classNodes)):
+        classNodes[i].SITsize = len(interM)
+        classNodes[i].subTypeSize = len(types) - 5 # no primitive types in subtype table
+        classNodes[i].subTypeOffset = i * 4 # assign each type a position in the subtype testing table
+
     # prep SIT
     for i in range(len(interM)):
         interM[i].methodOffset = i * 4
         interM[i].isInterM = True
 
-    # store SIT and subtype table size
-    for t in ASTs:
-        classInterNode = t[1].typeDcl
-        if classInterNode.__class__.__name__ == "ClassNode":
-            classInterNode.SITsize = len(interM)
-            classInterNode.subTypeSize = len(types) - 5 # no primitive types in subtype table
+    # init data section
+    for c in classNodes:
+        c.populateSizeAndFieldOffset()
+        c.populateMethodOffset()
 
     return arrayClassMemory(types)
 
diff --git a/TypeNodes.py b/TypeNodes.py
index 71c91b7b13ed435a4c4a8a936410f05a9c31687e..99fab645db712e1729f483ba14d6633671a8cda5 100644
--- a/TypeNodes.py
+++ b/TypeNodes.py
@@ -306,13 +306,12 @@ class ClassNode(ClassInterNode):
 
         # Calculating the size of objects of this class
         self.size += (len(self.fieldOffset))*4
-    
+
     # Populating method offset and creating class memory layout
     def populateMethodOffset(self):
         if hasattr(self, "data"):
             return
 
-        self.code = "" # For read-only section
         self.data = "" # For writeable data section
         if self.canonName == "java.lang.Object":
             self.data += p("global", "I_SIT_" + self.name)
@@ -391,15 +390,15 @@ class ClassNode(ClassInterNode):
             self.data += p("dd", "0") # 0 for False, 1 for True
 
         self.data += ";END OF CLASS MEMORY LAYOUT FOR CLASS " + self.name + "\n"
-        
+
 
     def codeGen(self):
         if hasattr(self, "code"):
             return
-        
+
 
         self.code = "" # For read-only section
-        
+
         # print("This is the super class: {}".format(self.superClass))
 
         # 4. Fill in the memory segment declared in step 1 and 2 with the addresses of the method implementations