heavily revised partitions.py -KL