Various code fixes intending to address memory leak and allocation issues. Memory usage growth should now be minimized to some degree when files are closed.