Code tidy-up and a script to run the memory tests.
Note that memory-test-7 currently fails. That's the next job.