Refactor compaction