Optimizations, targeted by profiling. Tests in samples dir do not currently work. New outputs do not match, but are better from all that I've looked at so far.