fix bug in repartition code