Fix compaction-related bugs