integreated sorting and compaction