More changes to avoid memory problems, still more stuff to do to make it pass tests.