Fixes a bug in the merge/compact algorithm