Various bug fixes to pass more tests.
Fix bugs to pass expansion tests.
Fix bugs to pass compaction tests.
Fix bugs to pass unit tests, do JSON comparison in test runner.