Started writing the re-partitioning algorithm