Try in-place diff and cost
Fixes
Fix MemoryError
Some other optimizations