Fixed bugs in compaction