Almost done.

Just needs the occurrence recording algorithm and more leak catching.