Terminate compaction

Compaction was:

1. Not correct.
2. Not terminating when correct.

This fixes both.