Added second layer to partition algorithm