Add some optimization.

It still might be that we need to write to a file to really do this well.