Compact method to compact history.

With this, we can free up some memory because old version might have
some references to otherwise unreferenced object.