I write it here but it's a general remark. There's virtually no error handling in this new code. We need to think what kind of error may occur during compaction and if we should care about them.

Also, here we do not follow a jquery convention to have err as the first argument of a callback.