diff --git a/examples/lj_func.py b/examples/lj_func.py
index 5ec2c46e69ffe4e8d89c3269f1e8b5435c6f81bb..97d72009dd5a2ebeeab57f2c4ee72c851c4b3457 100644
--- a/examples/lj_func.py
+++ b/examples/lj_func.py
@@ -19,7 +19,7 @@ sigma = 1.0
 epsilon = 1.0
 sigma6 = sigma ** 6
 
-psim = pairs.simulation("lj_ns")
+psim = pairs.simulation("lj_ns", debug=True)
 psim.add_real_property('mass', 1.0)
 psim.add_position('position')
 psim.add_vector_property('velocity')
diff --git a/src/pairs/__init__.py b/src/pairs/__init__.py
index 5bb8d848387e2e1a9c9716b840078f5be74cd238..98e050f763d8a0d64ab244ce37b96ebea28d8d93 100644
--- a/src/pairs/__init__.py
+++ b/src/pairs/__init__.py
@@ -2,5 +2,5 @@ from pairs.code_gen.cgen import CGen
 from pairs.sim.simulation import Simulation
 
 
-def simulation(ref, dims=3, timesteps=100):
-    return Simulation(CGen(f"{ref}.cpp"), dims, timesteps)
+def simulation(ref, dims=3, timesteps=100, debug=False):
+    return Simulation(CGen(f"{ref}.cpp", debug), dims, timesteps)
diff --git a/src/pairs/code_gen/cgen.py b/src/pairs/code_gen/cgen.py
index 51ada586a620b070d052c99c8c205f5cccf60f65..af7b1a631c67d6a728decec4f739111936ad8b72 100644
--- a/src/pairs/code_gen/cgen.py
+++ b/src/pairs/code_gen/cgen.py
@@ -32,8 +32,9 @@ class CGen:
             else 'bool'
         )
 
-    def __init__(self, output):
+    def __init__(self, output, debug=False):
         self.sim = None
+        self.debug = debug
         self.print = Printer(output)
 
     def assign_simulation(self, sim):
@@ -88,7 +89,15 @@ class CGen:
 
             self.print(f"void {module.name}({module_params}) {{")
             self.print.add_indent(4)
+
+            if self.debug:
+                self.generate_statement(Print(self.sim, module.name + " --- enter"))
+
             self.generate_statement(module.block)
+
+            if self.debug:
+                self.generate_statement(Print(self.sim, module.name + " --- exit"))
+
             self.print.add_indent(-4)
             self.print("}")
 
diff --git a/src/pairs/transformations/modules.py b/src/pairs/transformations/modules.py
index c463beadab29a0b0b6b32d08b535546fc005f49e..695bce0557bfba024dd7710fd2bf4b63a4d97af7 100644
--- a/src/pairs/transformations/modules.py
+++ b/src/pairs/transformations/modules.py
@@ -115,9 +115,9 @@ class AddResizeLogic(Mutator):
                     resizes = list(self.module_resizes[module].keys())
                     capacities = list(self.module_resizes[module].values())
                     resize_id = resizes[capacities.index(match_capacity)]
-                    return Branch(ast_node.sim, src < match_capacity,
-                                  blk_if=Block(ast_node.sim, ast_node),
-                                  blk_else=Block(ast_node.sim, ast_node.sim.resizes[resize_id].set(src)))
+                    return Branch(ast_node.sim, src + 1 >= match_capacity,
+                                  blk_if=Block(ast_node.sim, ast_node.sim.resizes[resize_id].set(src)),
+                                  blk_else=Block(ast_node.sim, ast_node))
 
         return ast_node
 
@@ -181,7 +181,8 @@ class ReplaceModulesByCalls(Mutator):
 
                 if properties.is_capacity(c):
                     for p in properties.all():
-                        sizes = [c, sim.ndims()] if p.type() == Type_Vector else [c]
+                        new_capacity = sum(properties.capacities)
+                        sizes = [new_capacity, sim.ndims()] if p.type() == Type_Vector else [new_capacity]
                         props_realloc += [Realloc(sim, p, reduce(operator.mul, sizes)), UpdateProperty(sim, p, sizes)]
 
                 resize_stmts.append(