major update -- i believe this fixed the major memory leak. i still need to make sure, and also verify that the code gives the exact same results as before