data-sort: moved cleanups out of the lock