I believe I just fixed the last memory leak inside the inner loops. I don't particularly care about the others for now.