good progress, need to fix the used_idx stuff