start regroup algorithm