Compacting algorithm (WIP)