Optimized compact()