cleanup before sort