Mem log fix and Memo Algo fix.

Fixes #19. Also adds some optimization (more like clean up) to hirshberg.